package com.example.jw_web.Control;


import com.example.jw_web.Servlet.MessageBoardServlet;
import com.example.jw_web.pojo.MessageBoard;
import com.example.jw_web.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@Component
@CrossOrigin(origins = "*")  //允许后端访问
public class messageBoard {

    @Autowired
    MessageBoardServlet messageBoardServlet;

    //留言
      @GetMapping("/message")
     public List<MessageBoard> sendMessages()
      {
          List<MessageBoard> messageBoards=new ArrayList<>();
          messageBoards= messageBoardServlet.getMessages();
          log.info("返回留言信息：  "+messageBoards.toString());
          return messageBoards; //返回一个MessageBoard的集合回去
      }

      //获取留言
      @PostMapping("/sendmessages")
      public  Result  getMessages(@RequestBody MessageBoard messageBoard)
      {
          log.info("存储留言：  "+messageBoard.toString());
          messageBoardServlet.saveMessages(messageBoard);
          return Result.success(null);
      }

}
